import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/pages/mine/push_setting/push_setting_controller.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:flutter_changdian_football/widget/switch/flutter_switch.dart';
import 'package:get/get.dart';

/// 推送设置
class PushSettingPage extends StatelessWidget {
  const PushSettingPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xffF8FAF9),
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: const Color(0xffF8FAF9),
        elevation: 0,
        title: Text(
          '推送设置',
          style: TextStyle(fontSize: 16.sp, color: const Color(0xff333333)),
        ),
        iconTheme: const IconThemeData(
          color: Color(0xff333333)
        ),
      ),
      body: GetBuilder<PushSettingController>(
        init: PushSettingController(),
        builder: (pushSettingController) {
          return SingleChildScrollView(
            padding: EdgeInsets.symmetric(horizontal: 17.w),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  width: double.infinity,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(12.r)
                  ),
                  child: _listTileWidget(leftText: '接收消息通知', isSelect: pushSettingController.userNotifySettingModel?.allSwitch, onTap: () {
                    pushSettingController.userNotifySet(0);
                  }),
                ),

                SizedBox(height: 10.w,),

                Container(
                  padding: EdgeInsets.symmetric(horizontal: 12.w),
                  child: Text('开启消息通知后，可以及时获得重要消息', style: TextStyle(fontSize: 12.sp, color: const Color(0xff999999)),),
                ),

                if (pushSettingController.userNotifySettingModel?.allSwitch == 'ON') ...[
                  SizedBox(height: 20.w,),

                  Container(
                    width: double.infinity,
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(12.r)
                    ),
                    child: Column(
                      children: [
                        _listTileWidget(leftText: '比赛消息', isSelect: pushSettingController.userNotifySettingModel?.matchNotify, onTap: () {
                          pushSettingController.userNotifySet(1);
                        }),
                        Container(
                          width: double.infinity,
                          height: 0.5.w,
                          color: const Color(0xffE5E5E5 ),
                          margin: EdgeInsets.symmetric(horizontal: 12.w),
                        ),
                        _listTileWidget(leftText: '俱乐部动态', isSelect: pushSettingController.userNotifySettingModel?.clubDynamicNotify, onTap: () {
                          pushSettingController.userNotifySet(2);
                        }),
                        Container(
                          width: double.infinity,
                          height: 0.5.w,
                          color: const Color(0xffE5E5E5 ),
                          margin: EdgeInsets.symmetric(horizontal: 12.w),
                        ),
                        _listTileWidget(leftText: '被点赞通知', isSelect: pushSettingController.userNotifySettingModel?.praiseNotify, onTap: () {
                          pushSettingController.userNotifySet(3);
                        }),
                        Container(
                          width: double.infinity,
                          height: 0.5.w,
                          color: const Color(0xffE5E5E5 ),
                          margin: EdgeInsets.symmetric(horizontal: 12.w),
                        ),
                        _listTileWidget(leftText: '被关注通知', isSelect: pushSettingController.userNotifySettingModel?.interestNotify, onTap: () {
                          pushSettingController.userNotifySet(4);
                        }),
                        Container(
                          width: double.infinity,
                          height: 0.5.w,
                          color: const Color(0xffE5E5E5 ),
                          margin: EdgeInsets.symmetric(horizontal: 12.w),
                        ),
                        _listTileWidget(leftText: '系统通知', isSelect: pushSettingController.userNotifySettingModel?.systemNotify, onTap: () {
                          pushSettingController.userNotifySet(5);
                        }),
                        Container(
                          width: double.infinity,
                          height: 0.5.w,
                          color: const Color(0xffE5E5E5 ),
                          margin: EdgeInsets.symmetric(horizontal: 12.w),
                        ),
                        _listTileWidget(leftText: '俱乐部审核消息', isSelect: pushSettingController.userNotifySettingModel?.clubCheckNotify, onTap: () {
                          pushSettingController.userNotifySet(6);
                        })
                      ],
                    ),
                  ),
                ],

                

              ],
            ),
          );
        }
      ),
    );
  }


  _listTileWidget({
    String leftText = '',
    String? isSelect,
    Function? onTap,
  }) {
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      onTap: () {
        onTap?.call();
      },
      child: Container(
        padding: EdgeInsets.symmetric(vertical: 12.w, horizontal: 12.w),
        child: Row(
          children: [
            SizedBox(
              child: Text(leftText, style: TextStyle(fontSize: 15.sp, color: const Color(0xff323232)),),
            ),
    
            const Spacer(),
    
            FlutterSwitch(
              value: isSelect == 'ON' ? true : false, 
              width: 40.w,
              height: 25.w,
              toggleSize: 20.w,
              padding: 2.w,
              inactiveColor: const Color(0xffe1e1e1),
              toggleColor: Colors.white,
              activeColor: const Color(0xff499360),
              onToggle: (v) {
                onTap?.call();
              }
            )
          ],
        ),
      ),
    );
  }


}